package com.rmd.dl.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.rmd.dl.domain.po.DlTopic;
import com.rmd.dl.service.TopicService;

import net.sf.json.JSONObject;


@Controller
@RequestMapping("topic")
public class TopicAction {
	
	@Autowired
	private TopicService topicService;
	
	//@ResponseBody
	@RequestMapping("/topicList")
	public JSONObject userList(@RequestBody DlTopic dlTopic,HttpServletResponse response) throws Exception {//@RequestBody UserDTO userDTO
		response.setContentType("application/json; charset=UTF-8");
		response.getWriter().print(topicService.queryList(dlTopic));
		return null;
		//return topicService.queryList(dlTopic);
	}
	
	/**
     * 话题详情
     */
    @RequestMapping(value = "/getTopicById")
    public JSONObject getTopicById(HttpServletRequest request, @RequestBody JSONObject requestObject,HttpServletResponse response) throws Exception {
    	Integer tid = requestObject.getInt("id");
    	response.setContentType("application/json; charset=UTF-8");
		response.getWriter().print(topicService.queryObject(tid));
		return null;
    }

    /**
     * 创建话题
     */
    //@BeforeAdviceController({UserInterceptor.class})
    @RequestMapping(value = "/create", method = RequestMethod.GET)
    public String create(HttpServletRequest request) {
        //request.setAttribute("sections", sectionService.findByShowStatus(true));
        return "topic/create";
    }
	
}

